ReEDS Scenarios on PV ICE Tool¶

Journal Not Finished: The below journal was made to avoid doing pre-analysis in the excel for the baseline creation (the excel has a tab where we multiplied by the DC:AC factors [1.1,1.3,1.3] for the ['distpv','dupv','upv'] and the added them for using in the Solar Futures analysis. However this journal is not finished (I marked where I stopped), and it saves the PCA data incorrectly (every 2 years). Leaving in case it becomes useful at some point in life.

To explore different scenarios for furture installation projections of PV (or any technology), ReEDS output data can be useful in providing standard scenarios. ReEDS installation projections are used in this journal as input data to the PV ICE tool.

Current sections include:

  1. ### Reading a cumulative capacity ReEDS output file
  2. ### Reading an annual built ReEDS output file
  3. ### Saving PCA data as PV ICE input format
  4. ### Saving State data as PV ICE input format
In [1]:
import numpy as np
import pandas as pd
import os,sys
import matplotlib.pyplot as plt
plt.rcParams.update({'font.size': 22})
plt.rcParams['figure.figsize'] = (12, 8)
In [2]:
import os
from pathlib import Path

testfolder = str(Path().resolve().parent.parent.parent / 'PV_ICE' / 'TEMP')

print ("Your simulation will be stored in %s" % testfolder)
Your simulation will be stored in C:\Users\sayala\Documents\GitHub\PV_ICE\PV_ICE\TEMP

Reading a ReEDS cumulative capacity output file¶

This reEDS output file is the cumulative capacity every other year. To get GW/yr installed, we need to take the difference between the years, then divide by 2. This is less accurate than getting an "annual built" data file because the cumulative capacity accounts for 30 year lifetime removal from field (default ReEDS assumption). This munging also neglects PCA region.

In [3]:
#We need to come up with a default location to save ReEDS output files
#reedsFile = str(Path().resolve().parent.parent.parent.parent / 'December Core Scenarios ReEDS Outputs Solar Futures v3a.xlsx')
#print ("Input file is stored in %s" % reedsFile)
reedsFile = str(Path().resolve().parent.parent.parent/ 'PV_ICE' / 'baselines' / 'SupportingMaterial' / '100REby2035-cumulative.csv')
print ("Input file is stored in %s" % reedsFile)
Input file is stored in C:\Users\sayala\Documents\GitHub\PV_ICE\PV_ICE\baselines\SupportingMaterial\100REby2035-cumulative.csv
In [4]:
REEDSInput = pd.read_csv(reedsFile)
REEDSInput.head
Out[4]:
<bound method NDFrame.head of       scenario  year   PCA  Capacity (GW)
0     a1_RE100  2010    p1       0.000016
1     a1_RE100  2010   p10       0.486023
2     a1_RE100  2010  p100       0.000000
3     a1_RE100  2010  p101       0.021315
4     a1_RE100  2010  p102       0.014625
...        ...   ...   ...            ...
8437    a1_Ref  2050   p95      38.563516
8438    a1_Ref  2050   p96      16.298854
8439    a1_Ref  2050   p97      18.744921
8440    a1_Ref  2050   p98       6.378485
8441    a1_Ref  2050   p99      28.449829

[8442 rows x 4 columns]>

Aggregate down to simple MW Installed input¶

In [5]:
rawdf = REEDSInput.copy()

#currently, we're ignoring region, so drop PCA
rawdf.drop(columns=['PCA'], inplace=True)

#aggregate and sum by scenarios and year to get an annual (bi-annual) installation by scenario
df = rawdf.groupby(['scenario', 'year'])['Capacity (GW)'].sum()
df_evens = pd.DataFrame(df)
df_evens_byscen = df.unstack(level='scenario')#this df contains all the scenarios, even years only
print(df_evens_byscen)
scenario     a1_RE100      a1_RE95      a1_Ref
year                                          
2010         1.246592     1.246592    1.246592
2012         6.242318     6.242318    6.242318
2014        16.090783    16.090783   16.090783
2016        34.276154    34.276154   34.276154
2018        52.093001    52.093001   52.093001
2020        83.778187    83.778187   83.533329
2022       146.553694   146.553694  102.993795
2024       191.078858   191.078858  128.602753
2026       326.268392   326.268392  177.112068
2028       431.634770   431.634770  230.392738
2030       580.819921   580.819921  309.015319
2032       702.410947   702.410947  333.157319
2034       812.257622   812.257622  354.101299
2036       934.894845   934.894845  385.447237
2038      1078.186255  1078.186255  417.757467
2040      1237.253347  1237.253347  464.569087
2042      1283.271124  1283.384991  512.675339
2044      1320.858174  1322.752809  569.486607
2046      1363.860206  1374.601619  614.658599
2048      1418.708071  1421.546054  683.068153
2050      1485.376422  1471.914866  731.232567

Take the difference and Divide by 2¶

The file provided is cumulative installs, therefore we need to take the difference between years

In [6]:
#take the difference between years to get the annual installs (not cumulative)
#grab scenario names
SCEN = df_evens.index.levels[0]
#len(SCEN)
#create a for loop to iterate through all the provided scenarios
for i in range(len(SCEN)):
    df_evens_byscen[SCEN[i]+'_added_cap(GW)'] = df[SCEN[i]].diff() #takes diff between rows and creates new column
#print(df_evens_byscen)
df_addedCap_evens = df_evens_byscen.filter(regex = 'added_cap') #create df of just added capacity, removes multiIndex
print(df_addedCap_evens)
scenario  a1_RE100_added_cap(GW)  a1_RE95_added_cap(GW)  a1_Ref_added_cap(GW)
year                                                                         
2010                         NaN                    NaN                   NaN
2012                    4.995726               4.995726              4.995726
2014                    9.848465               9.848465              9.848465
2016                   18.185371              18.185371             18.185371
2018                   17.816847              17.816847             17.816847
2020                   31.685186              31.685186             31.440328
2022                   62.775507              62.775507             19.460466
2024                   44.525164              44.525164             25.608958
2026                  135.189534             135.189534             48.509315
2028                  105.366378             105.366378             53.280670
2030                  149.185151             149.185151             78.622581
2032                  121.591026             121.591026             24.142000
2034                  109.846674             109.846674             20.943980
2036                  122.637223             122.637223             31.345937
2038                  143.291410             143.291410             32.310230
2040                  159.067093             159.067093             46.811620
2042                   46.017777              46.131643             48.106252
2044                   37.587050              39.367819             56.811268
2046                   43.002032              51.848810             45.171992
2048                   54.847865              46.944435             68.409554
2050                   66.668351              50.368813             48.164414

Because we prefer to use real world data whereever possible, anything prior to the current year will use real world installs. Therefore, we can ignore the NaN values in 2010.

Now we divide this added installations in half.

In [7]:
df_annualAdds_evens = df_addedCap_evens/2
print(df_annualAdds_evens)
scenario  a1_RE100_added_cap(GW)  a1_RE95_added_cap(GW)  a1_Ref_added_cap(GW)
year                                                                         
2010                         NaN                    NaN                   NaN
2012                    2.497863               2.497863              2.497863
2014                    4.924232               4.924232              4.924232
2016                    9.092685               9.092685              9.092685
2018                    8.908424               8.908424              8.908424
2020                   15.842593              15.842593             15.720164
2022                   31.387753              31.387753              9.730233
2024                   22.262582              22.262582             12.804479
2026                   67.594767              67.594767             24.254658
2028                   52.683189              52.683189             26.640335
2030                   74.592576              74.592576             39.311291
2032                   60.795513              60.795513             12.071000
2034                   54.923337              54.923337             10.471990
2036                   61.318612              61.318612             15.672969
2038                   71.645705              71.645705             16.155115
2040                   79.533546              79.533546             23.405810
2042                   23.008888              23.065822             24.053126
2044                   18.793525              19.683909             28.405634
2046                   21.501016              25.924405             22.585996
2048                   27.423932              23.472217             34.204777
2050                   33.334176              25.184406             24.082207

Create the odd years¶

In [8]:
#Now create the odd years by duplicating the even years and changing the index
df_odds = df_annualAdds_evens.copy()
df_odds.index = df_odds.index-1 #set the index = one year less
print(df_odds)
scenario  a1_RE100_added_cap(GW)  a1_RE95_added_cap(GW)  a1_Ref_added_cap(GW)
year                                                                         
2009                         NaN                    NaN                   NaN
2011                    2.497863               2.497863              2.497863
2013                    4.924232               4.924232              4.924232
2015                    9.092685               9.092685              9.092685
2017                    8.908424               8.908424              8.908424
2019                   15.842593              15.842593             15.720164
2021                   31.387753              31.387753              9.730233
2023                   22.262582              22.262582             12.804479
2025                   67.594767              67.594767             24.254658
2027                   52.683189              52.683189             26.640335
2029                   74.592576              74.592576             39.311291
2031                   60.795513              60.795513             12.071000
2033                   54.923337              54.923337             10.471990
2035                   61.318612              61.318612             15.672969
2037                   71.645705              71.645705             16.155115
2039                   79.533546              79.533546             23.405810
2041                   23.008888              23.065822             24.053126
2043                   18.793525              19.683909             28.405634
2045                   21.501016              25.924405             22.585996
2047                   27.423932              23.472217             34.204777
2049                   33.334176              25.184406             24.082207
In [9]:
#put the evens and odds together, sort by year
df_allyrs = pd.concat([df_annualAdds_evens, df_odds])
df_allyrs.sort_index(axis=0, inplace=True)
#df_allyrs_byscen = df_allyrs.unstack(level=0)
#print(df_allyrs_byscen)

#modify by DC:AC ratio(1.2 avg) and 85% average marketshare of c-Si technology and convert to MW
df_cSi_installs = df_allyrs*1.2*0.85*1000
print(df_cSi_installs)
scenario  a1_RE100_added_cap(GW)  a1_RE95_added_cap(GW)  a1_Ref_added_cap(GW)
year                                                                         
2009                         NaN                    NaN                   NaN
2010                         NaN                    NaN                   NaN
2011                 2547.820449            2547.820449           2547.820449
2012                 2547.820449            2547.820449           2547.820449
2013                 5022.716968            5022.716968           5022.716968
2014                 5022.716968            5022.716968           5022.716968
2015                 9274.539118            9274.539118           9274.539118
2016                 9274.539118            9274.539118           9274.539118
2017                 9086.592100            9086.592100           9086.592100
2018                 9086.592100            9086.592100           9086.592100
2019                16159.444770           16159.444770          16034.567311
2020                16159.444770           16159.444770          16034.567311
2021                32015.508487           32015.508487           9924.837597
2022                32015.508487           32015.508487           9924.837597
2023                22707.833880           22707.833880          13060.568829
2024                22707.833880           22707.833880          13060.568829
2025                68946.662206           68946.662206          24739.750702
2026                68946.662206           68946.662206          24739.750702
2027                53736.853006           53736.853006          27173.141573
2028                53736.853006           53736.853006          27173.141573
2029                76084.427036           76084.427036          40097.516316
2030                76084.427036           76084.427036          40097.516316
2031                62011.423352           62011.423352          12312.419957
2032                62011.423352           62011.423352          12312.419957
2033                56021.803858           56021.803858          10681.429981
2034                56021.803858           56021.803858          10681.429981
2035                62544.983737           62544.983737          15986.427974
2036                62544.983737           62544.983737          15986.427974
2037                73078.619190           73078.619190          16478.217382
2038                73078.619190           73078.619190          16478.217382
2039                81124.217218           81124.217218          23873.926119
2040                81124.217218           81124.217218          23873.926119
2041                23469.066030           23527.138071          24534.188658
2042                23469.066030           23527.138071          24534.188658
2043                19169.395344           20077.587485          28973.746541
2044                19169.395344           20077.587485          28973.746541
2045                21931.036440           26442.892874          23037.716088
2046                21931.036440           26442.892874          23037.716088
2047                27972.410948           23941.661800          34888.872539
2048                27972.410948           23941.661800          34888.872539
2049                34000.859042           25688.094448          24563.851264
2050                34000.859042           25688.094448          24563.851264
In [10]:
#output the file
df_cSi_installs.to_csv('output_reeds4PVICE.csv', index=True)

Reading a ReEDS annual built capacity file¶

This data file is the "annual built capacity", or the additions (not net additions) to the grid. This is an annual number reported biannually, so the assumption is that the previous odd year installed the same amount of PV capacity.

In [11]:
reedsFile = str(Path().resolve().parent.parent.parent/ 'PV_ICE' / 'baselines' / 'SupportingMaterial' / '100REby2035-annuals.csv')
print ("Input file is stored in %s" % reedsFile)
REEDSInput = pd.read_csv(reedsFile)
REEDSInput.head
Input file is stored in C:\Users\sayala\Documents\GitHub\PV_ICE\PV_ICE\baselines\SupportingMaterial\100REby2035-annuals.csv
Out[11]:
<bound method NDFrame.head of          tech  scenario region  year  Capacity (GW)
0         upv  a1_RE100     p1  2012       0.000000
1         upv  a1_RE100     p1  2014       0.000000
2         upv  a1_RE100     p1  2016       0.000000
3         upv  a1_RE100     p1  2018       0.000000
4         upv  a1_RE100     p1  2020       0.012500
...       ...       ...    ...   ...            ...
24115  distpv    a1_Ref    p99  2042       0.131880
24116  distpv    a1_Ref    p99  2044       0.146862
24117  distpv    a1_Ref    p99  2046       0.257416
24118  distpv    a1_Ref    p99  2048       0.112180
24119  distpv    a1_Ref    p99  2050       0.213627

[24120 rows x 5 columns]>
In [12]:
rawdf = REEDSInput.copy()

#currently, we're ignoring region, so drop PCA
rawdf.drop(columns=['region'], inplace=True)

#aggregate and sum by scenarios and year to get an annual (bi-annual) installation by scenario
df = pd.DataFrame(rawdf.groupby(['tech', 'scenario', 'year'])['Capacity (GW)'].sum())
df.head
Out[12]:
<bound method NDFrame.head of                       Capacity (GW)
tech   scenario year               
distpv a1_RE100 2012       1.328463
                2014       1.872017
                2016       3.352236
                2018       4.041324
                2020       2.483214
...                             ...
upv    a1_Ref   2042      21.048414
                2044      26.540308
                2046      22.716836
                2048      36.073316
                2050      33.473629

[180 rows x 1 columns]>

Now we multiply each technology by it's respective DC:AC ratio, because distributed PV (i.e. rooftop) in ReEDS is reported in AC with a 1.1 DC:AC ratio. We install in DC, therefore, we multiply ReEDS output by 1.1. For both types of utility PV (Distributed UPV and UPV), the DC:AC ratio is 1.3.

In [13]:
#create a litte dataframe of the factors with index that matches tech names
dc_ac = pd.DataFrame({'factor':[1.1,1.3,1.3]}, index=['distpv','dupv','upv'])
#multiply techs by DC:AC ratios
df_dc = df.mul(dc_ac['factor'], level=0, axis='index')
print(df_dc)
                      Capacity (GW)
tech   scenario year               
distpv a1_RE100 2012       1.461310
                2014       2.059218
                2016       3.687460
                2018       4.445456
                2020       2.731536
...                             ...
upv    a1_Ref   2042      27.362938
                2044      34.502400
                2046      29.531887
                2048      46.895311
                2050      43.515717

[180 rows x 1 columns]

Now we're in DC, we can sum the techs for each scenario and year.

In [14]:
df_byscen = pd.DataFrame(df_dc.groupby(['scenario', 'year'])['Capacity (GW)'].sum())
df_evens_byscen = df_byscen.unstack(level='scenario')
#print(df_evens_byscen)

This gives us the annual added capacity, by scenario, but only on even years. ReEDS recommendation is to back duplicate the installation, i.e. the same amount of PV is installed in 2049 and 2050. Now we create an odd year data set.

In [15]:
#Now create the odd years by duplicating the even years and changing the index
df_odds = df_evens_byscen.copy()
df_odds.index = df_odds.index-1 #set the index = one year less
#print(df_odds)

Now concatinate the two dataframes, and reorder by year number.

In [16]:
#put the evens and odds together, sort by year
df_allyrs = pd.concat([df_evens_byscen, df_odds])
df_allyrs.sort_index(axis=0, inplace=True)
#print(df_allyrs)

Finally, we only consider c-Si installations right now, and the historical average is 85% c-Si market share in the US (most of the rest is CdTe). Therefore, we multiply everything by 0.85 to account for only c-Si material.

In [17]:
#multiply by 85% average marketshare of c-Si technology and convert to MW
df_cSi_installs = df_allyrs*0.85*1000
print(df_cSi_installs)
         Capacity (GW)                            
scenario      a1_RE100       a1_RE95        a1_Ref
year                                              
2011       2534.300109   2534.300109   2534.300109
2012       2534.300109   2534.300109   2534.300109
2013       5123.033732   5123.033732   5123.033732
2014       5123.033732   5123.033732   5123.033732
2015       9477.537310   9477.537310   9477.537310
2016       9477.537310   9477.537310   9477.537310
2017       9156.783125   9156.783125   9156.783125
2018       9156.783125   9156.783125   9156.783125
2019      17083.918896  17083.918896  16948.634981
2020      17083.918896  17083.918896  16948.634981
2021      34309.524105  34309.524105  10377.963980
2022      34309.524105  34309.524105  10377.963980
2023      24236.415968  24236.415968  13785.212152
2024      24236.415968  24236.415968  13785.212152
2025      74146.088485  74146.088485  26255.267659
2026      74146.088485  74146.088485  26255.267659
2027      57401.301559  57401.301559  28623.947560
2028      57401.301559  57401.301559  28623.947560
2029      81197.986505  81197.986505  42212.166639
2030      81197.986505  81197.986505  42212.166639
2031      66012.061777  66012.061777  12171.474714
2032      66012.061777  66012.061777  12171.474714
2033      59935.855225  59935.855225  10817.116828
2034      59935.855225  59935.855225  10817.116828
2035      67039.351511  67039.351511  16600.916044
2036      67039.351511  67039.351511  16600.916044
2037      78553.287849  78553.287849  17236.185916
2038      78553.287849  78553.287849  17236.185916
2039      87426.894743  87426.894743  25405.746051
2040      87426.894743  87426.894743  25405.746051
2041      26258.301319  26321.212680  27412.184132
2042      26258.301319  26321.212680  27412.184132
2043      23596.728957  24580.603779  34218.109410
2044      23596.728957  24580.603779  34218.109410
2045      29613.993354  34501.837845  30812.896325
2046      29613.993354  34501.837845  30812.896325
2047      35203.627130  30836.982267  42696.460528
2048      35203.627130  30836.982267  42696.460528
2049      51033.756041  42028.261028  40675.047032
2050      51033.756041  42028.261028  40675.047032
In [18]:
#output the file
df_cSi_installs.to_csv('output_reeds4PVICE.csv', index=True)

Save Input Files by PCA Region for Mapping¶

In [19]:
rawdf2 = REEDSInput.copy()

#aggregate and sum by scenarios and year to get an annual (bi-annual) installation by scenario
df_byregion = pd.DataFrame(rawdf2.groupby(['tech', 'scenario', 'year', 'region'])['Capacity (GW)'].sum())
df_byregion.head
Out[19]:
<bound method NDFrame.head of                              Capacity (GW)
tech   scenario year region               
distpv a1_RE100 2012 p1           0.004689
                     p10          0.150564
                     p100         0.000000
                     p101         0.008424
                     p102         0.004160
...                                    ...
upv    a1_Ref   2050 p95          1.309897
                     p96          0.732107
                     p97          1.500091
                     p98          0.580900
                     p99          3.798898

[24120 rows x 1 columns]>

Multiply the dataframe by the tech factors AC to DC ratio here so that it can be dropped and simplify the df

In [21]:
#create a litte dataframe of the factors with index that matches tech names
dc_ac = pd.DataFrame({'factor':[1.1,1.3,1.3]}, index=['distpv','dupv','upv'])
#multiply techs by DC:AC ratios
df_byregion_dc = df_byregion.mul(dc_ac['factor'], level=0, axis='index')
In [23]:
#now weight by c-si technology ~85% marketshare
c_si = pd.DataFrame({'factor':[1.0,0.85,0.85]}, index=['distpv','dupv','upv']) 
#distpv = residential, which is pretty much all c-Si, others are utility, so 85%
df_byregion_dc_si = df_byregion_dc.mul(c_si['factor'], level=0, axis='index')
In [24]:
df_byregion_dc_si_mw = df_byregion_dc_si*1000 #reeds outputs are in GW, so changing to MW for PV ICE

Now everything is c-Si in DC, can use groupby sum to combine the techs

In [25]:
#after multiplying to get dc, sum the installs across techs, to simplify for PCA region analysis
df_dc_byregion = pd.DataFrame(df_byregion_dc_si_mw.groupby(['scenario', 'year', 'region'])['Capacity (GW)'].sum()) 
df_dc_byregion.rename(columns = {'Capacity (GW)':'new_Installed_Capacity_[MW]'}, inplace = True)
df_dc_byregion
Out[25]:
new_Installed_Capacity_[MW]
scenario year region
a1_RE100 2012 p1 5.158000
p10 314.684500
p100 0.000000
p101 21.918750
p102 4.575500
... ... ... ...
a1_Ref 2050 p95 1477.385354
p96 877.839139
p97 1755.434607
p98 745.414000
p99 4432.771983

8040 rows × 1 columns

Loading Module Baseline. Will be used later to populate all the columsn otehr than 'new_InstalledCapacity[MW]' which will be supplied by the REEDS model¶

In [31]:
import PV_ICE
r1 = PV_ICE.Simulation(name='Simulation1', path=testfolder)
#r1.createScenario(name='US', file=r'..\baselines\baseline_modules_US_100RE2050.csv')
r1.createScenario(name='US', massmodulefile=r'..\baselines\baseline_modules_mass_US.csv') # Don't need this one specifically 
baseline = r1.scenario['US'].dataIn_m
baseline.set_index('year', inplace=True)
history = pd.DataFrame(baseline['new_Installed_Capacity_[MW]'].loc[1995:2020]) #preserve historical installs
baseline = baseline.drop(columns=['new_Installed_Capacity_[MW]'])
baseline.index = pd.PeriodIndex(baseline.index, freq='A')  # A -- Annual
history
path = C:\Users\sayala\Documents\GitHub\PV_ICE\PV_ICE\TEMP
Deprecation warning: file has been deprecated as of v 0.3 as an input to class Scenario and will be fully removed for v 0.4; Use 'massmodulefile' instead. 
 Internally renaming as massmodulefile to continue
Out[31]:
new_Installed_Capacity_[MW]
year
1995 12.500000
1996 9.667667
1997 11.622000
1998 11.781000
1999 16.884667
2000 20.926667
2001 27.985000
2002 42.476000
2003 59.745000
2004 94.752000
2005 96.581173
2006 98.213072
2007 324.232748
2008 314.585109
2009 431.244804
2010 719.844438
2011 1781.377078
2012 3064.162281
2013 4037.449113
2014 3722.199485
2015 6834.328813
2016 12897.665950
2017 9784.506215
2018 9352.529448
2019 10949.782340
2020 14903.790000
In [36]:
r1.scenario['US'].dataIn_m.loc[2018:2023]
Out[36]:
new_Installed_Capacity_[MW] mod_eff mod_reliability_t50 mod_reliability_t90 mod_degradation mod_lifetime mod_MFG_eff mod_Repair mod_MerchantTail mod_EOL_collection_eff ... mod_EOL_pg1_landfill mod_EOL_pg2_stored mod_EOL_pg3_reMFG mod_EOL_pg4_recycled mod_EOL_reMFG_yield mod_EOL_sp_reMFG_recycle mod_EOL_pb1_landfill mod_EOL_pb2_stored mod_EOL_pb3_reMFG mod_EOL_pb4_recycled
year
2018 9352.529448 18.400000 28.0 33.0 0.3 31.0 98.0 0.0 0.0 15.0 ... 60.0 0.0 0.0 40.0 0.0 100.0 60.0 0.0 0.0 40.0
2019 10949.782340 19.200000 28.0 33.0 0.3 32.4 98.0 0.0 0.0 15.0 ... 60.0 0.0 0.0 40.0 0.0 100.0 60.0 0.0 0.0 40.0
2020 14903.790000 20.000000 33.0 38.0 0.5 35.0 98.0 0.0 0.0 15.0 ... 60.0 0.0 0.0 40.0 0.0 100.0 60.0 0.0 0.0 40.0
2021 16455.560000 20.900000 33.0 38.0 0.5 35.0 98.0 0.0 0.0 15.0 ... 60.0 0.0 0.0 40.0 0.0 100.0 60.0 0.0 0.0 40.0
2022 15227.230000 21.480425 33.0 38.0 0.5 35.0 98.0 0.0 0.0 15.0 ... 60.0 0.0 0.0 40.0 0.0 100.0 60.0 0.0 0.0 40.0
2023 15224.020000 21.885874 33.0 38.0 0.5 35.0 98.0 0.0 0.0 15.0 ... 60.0 0.0 0.0 40.0 0.0 100.0 60.0 0.0 0.0 40.0

6 rows × 21 columns

Now join the pca region to the module file and create files by scenario and pca region

In [37]:
df_odds = df_evens_byscen.copy()
df_odds.index = df_odds.index-1 #set the index = one year less
#put the evens and odds together, sort by year
df_allyrs = pd.concat([df_evens_byscen, df_odds])
df_allyrs.sort_index(axis=0, inplace=True)
In [38]:
for scenarios in range(len(df_dc_byregion.index.levels[0])): # iterate over the scenarios (3 scenarios)
    scenario_name = df_dc_byregion.index.levels[0][scenarios] #assigns the current scenario name to a variable
    for pcas in range(len(df_dc_byregion.index.levels[2])): #iterate over pca regions (134 pca regions)
        pca = df_dc_byregion.index.levels[2][pcas] #assigns current pca name to a variable
        filetitle = scenario_name+'_'+pca +'.csv'
        subtestfolder = os.path.join(testfolder, 'ColePCAs')
        if not os.path.exists(subtestfolder):
            os.makedirs(subtestfolder)
        filetitle = os.path.join(subtestfolder, filetitle) #these lines create a folder and file naming structure
        
        B = df_dc_byregion.xs(scenario_name,level='scenario') #takes cross section by the scenario name
        A = B.xs(pca,level='region') #takes cross section by the pca region
        A.name = 'new_Installed_Capacity_[MW]' #makes sure the name is right for pv ice
        A = pd.DataFrame(A)
        A.index=pd.PeriodIndex(A.index, freq='A')
        A = pd.DataFrame(A)
        # Add other columns
        A = pd.concat([A.reindex(baseline.index), baseline], axis=1)
        A.update(history) #not working yet
        #A.replace((['new_Installed_Capacity_[MW]'][1995:2020]), history, inplace=True)
        
        header = "year,new_Installed_Capacity_[MW],mod_eff,mod_reliability_t50,mod_reliability_t90,"\
    "mod_degradation,mod_lifetime,mod_MFG_eff,mod_EOL_collection_eff,mod_EOL_collected_recycled,"\
    "mod_Repair,mod_MerchantTail,mod_Reuse\n"\
    "year,MW,%,years,years,%,years,%,%,%,%,%,%\n"

        with open(filetitle, 'w', newline='') as ict:
    # Write the header lines, including the index variable for
    # the last one if you're letting Pandas produce that for you.
    # (see above).
            for line in header:
                ict.write(line)

        #    savedata.to_csv(ict, index=False)
            A.to_csv(ict, header=False)
        

UPDATED UNTIL HERE on Nov 29, 2022¶

Save Input Files By States¶

Reassign data from REEDS Input, as we need one of the columns we dropped.¶

In [41]:
REEDSInput
Out[41]:
tech scenario region year Capacity (GW)
0 upv a1_RE100 p1 2012 0.000000
1 upv a1_RE100 p1 2014 0.000000
2 upv a1_RE100 p1 2016 0.000000
3 upv a1_RE100 p1 2018 0.000000
4 upv a1_RE100 p1 2020 0.012500
... ... ... ... ... ...
24115 distpv a1_Ref p99 2042 0.131880
24116 distpv a1_Ref p99 2044 0.146862
24117 distpv a1_Ref p99 2046 0.257416
24118 distpv a1_Ref p99 2048 0.112180
24119 distpv a1_Ref p99 2050 0.213627

24120 rows × 5 columns

In [40]:
rawdf = REEDSInput.copy()
#rawdf.drop(columns=['State'], inplace=True)
rawdf.drop(columns=['Tech'], inplace=True)
rawdf.set_index(['Scenario','Year','PCA', 'State'], inplace=True)
rawdf.head(21)
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Input In [40], in <cell line: 4>()
      1 rawdf = REEDSInput.copy()
      2 #rawdf.drop(columns=['State'], inplace=True)
      3 #rawdf.drop(columns=['Tech'], inplace=True)
----> 4 rawdf.set_index(['Scenario','Year','PCA', 'State'], inplace=True)
      5 rawdf.head(21)

File ~\Anaconda3\lib\site-packages\pandas\util\_decorators.py:311, in deprecate_nonkeyword_arguments.<locals>.decorate.<locals>.wrapper(*args, **kwargs)
    305 if len(args) > num_allow_args:
    306     warnings.warn(
    307         msg.format(arguments=arguments),
    308         FutureWarning,
    309         stacklevel=stacklevel,
    310     )
--> 311 return func(*args, **kwargs)

File ~\Anaconda3\lib\site-packages\pandas\core\frame.py:5503, in DataFrame.set_index(self, keys, drop, append, inplace, verify_integrity)
   5500                 missing.append(col)
   5502 if missing:
-> 5503     raise KeyError(f"None of {missing} are in the columns")
   5505 if inplace:
   5506     frame = self

KeyError: "None of ['Scenario', 'Year', 'PCA', 'State'] are in the columns"

Group data so we can work with the States instead¶

In [ ]:
#df = rawdf.groupby(['Scenario','State', 'Year'])['Capacity (GW)'].sum(axis=0)
df = rawdf.groupby(['Scenario','State', 'Year'])['Capacity (GW)'].sum()
df = pd.DataFrame(df)
df.head()

For each Scenario and for each STATE, combine with baseline and save as input file¶

In [ ]:
for ii in range (len(df.unstack(level=2))):   
    STATE = df.unstack(level=2).iloc[ii].name[1]
    SCEN = df.unstack(level=2).iloc[ii].name[0]
    SCEN=SCEN.replace('+', '_')
    filetitle = SCEN+'_'+STATE +'.csv'
    
    subtestfolder = os.path.join(testfolder, 'STATEs')
    if not os.path.exists(subtestfolder):
        os.makedirs(subtestfolder)
    filetitle = os.path.join(subtestfolder, filetitle)

    A = df.unstack(level=2).iloc[ii]
    A = A.droplevel(level=0)
    A.name = 'new_Installed_Capacity_[MW]'
    A = pd.DataFrame(A)
    A.index=pd.PeriodIndex(A.index, freq='A')
    A = pd.DataFrame(A)
    A['new_Installed_Capacity_[MW]'] = A['new_Installed_Capacity_[MW]'] * 0.85 # marketshares['Si']
    A['new_Installed_Capacity_[MW]'] = A['new_Installed_Capacity_[MW]'] * 1000   # ReEDS file is in GW.
    # Add other columns
    A = pd.concat([A, baseline.reindex(A.index)], axis=1)
    
    
    header = "year,new_Installed_Capacity_[MW],mod_eff,mod_reliability_t50,mod_reliability_t90,"\
    "mod_degradation,mod_lifetime,mod_MFG_eff,mod_EOL_collection_eff,mod_EOL_collected_recycled,"\
    "mod_Repair,mod_MerchantTail,mod_Reuse\n"\
    "year,MW,%,years,years,%,years,%,%,%,%,%,%\n"

    with open(filetitle, 'w', newline='') as ict:
    # Write the header lines, including the index variable for
    # the last one if you're letting Pandas produce that for you.
    # (see above).
        for line in header:
            ict.write(line)

        #    savedata.to_csv(ict, index=False)
        A.to_csv(ict, header=False)

Saving US Baseline¶

Create a copy of the REEDS Input and modify structure for PCA focus¶

In [ ]:
rawdf = REEDSInput.copy()
#rawdf.drop(columns=['State'], inplace=True)
rawdf.drop(columns=['Tech'], inplace=True)
rawdf.set_index(['Scenario','Year'], inplace=True)
rawdf.head(21)
In [ ]:
#df = rawdf.groupby(['Scenario','Year'])['Capacity (GW)'].sum(axis=0)
df = rawdf.groupby(['Scenario','Year'])['Capacity (GW)'].sum()

Loading Module Baseline. Will be used later to populate all the columsn other than 'new_InstalledCapacity[MW]' which will be supplied by the REEDS model¶

In [ ]:
import PV_ICE
r1 = PV_ICE.Simulation(name='Simulation1', path=testfolder)
r1.createScenario(name='US', file=r'..\baselines\SolarFutures_2021\baseline_modules_US_Reeds.csv')
baseline = r1.scenario['US'].data
baseline = baseline.drop(columns=['new_Installed_Capacity_[MW]'])
baseline.set_index('year', inplace=True)
baseline.index = pd.PeriodIndex(baseline.index, freq='A')  # A -- Annual
baseline.head()

For each Scenario, combine with baseline and save as input file¶¶

In [ ]:
for ii in range (len(df.unstack(level=1))):
    SCEN = df.unstack(level=1).index[ii]
    SCEN=SCEN.replace('+', '_')
    filetitle = SCEN+'.csv'
    
    subtestfolder = os.path.join(testfolder, 'USA')
    if not os.path.exists(subtestfolder):
        os.makedirs(subtestfolder)
    filetitle = os.path.join(subtestfolder, filetitle)
    
    A = df.unstack(level=1).iloc[ii]

    A.name = 'new_Installed_Capacity_[MW]'
    A = pd.DataFrame(A)
    A.index=pd.PeriodIndex(A.index, freq='A')
    A = pd.DataFrame(A)
    A['new_Installed_Capacity_[MW]'] = A['new_Installed_Capacity_[MW]'] * 0.85 # marketshares['Si']
    A['new_Installed_Capacity_[MW]'] = A['new_Installed_Capacity_[MW]'] * 1000   # ReEDS file is in GW.
    # Add other columns
    A = pd.concat([A, baseline.reindex(A.index)], axis=1)
   
    header = "year,new_Installed_Capacity_[MW],mod_eff,mod_reliability_t50,mod_reliability_t90,"\
    "mod_degradation,mod_lifetime,mod_MFG_eff,mod_EOL_collection_eff,mod_EOL_collected_recycled,"\
    "mod_Repair,mod_MerchantTail,mod_Reuse\n"\
    "year,MW,%,years,years,%,years,%,%,%,%,%,%\n"

    with open(filetitle, 'w', newline='') as ict:
    # Write the header lines, including the index variable for
    # the last one if you're letting Pandas produce that for you.
    # (see above).
        for line in header:
            ict.write(line)

        #    savedata.to_csv(ict, index=False)
        A.to_csv(ict, header=False)
In [ ]:
 
In [ ]: